﻿using B.S.Data.MES.API.Applications.QualityManagement.ExamineProjectCommand.Commands;
using B.S.Domain.BasicData.QualityManagement;
using B.S.Infratrctrue;
using B.S.Requst;
using MediatR;

namespace B.S.Data.MES.API.Applications.QualityManagement.ExamineProjectCommand.CommandHandlers
{
    public class CreateExamineProjectCommandHandler : IRequestHandler<CreateExamineProjectCommand, APIRequst<int>>
    {
        private readonly IBaseRepository<ExamineProject> _examineprojectRepository;
        public CreateExamineProjectCommandHandler(IBaseRepository<ExamineProject> examineprojectRepository)
        {
            _examineprojectRepository = examineprojectRepository;
        }
        public async Task<APIRequst<int>> Handle(CreateExamineProjectCommand request, CancellationToken cancellationToken)
        {
            APIRequst<int> result = new APIRequst<int>();
            result.Code = RequstCode.成功;
            result.Msg = RequstCode.成功.ToString();

            ExamineProject project = new ExamineProject();
            project.ExamineProjectName=request.ExamineProjectName;
            project.ExamineId=request.ExamineId;
            project.ProjectMethod=request.ProjectMethod;
            project.ProjectStandard=request.ProjectStandard;
            project.Unit=request.Unit;
            project.UpperLimit=request.UpperLimit;
            project.LowerLimit=request.LowerLimit;
            project.ProjectRemark=request.ProjectRemark;
            project.CreateName = request.CreateName;
            project.CreateTime= DateTime.Now;

           await _examineprojectRepository.Add(project);
            return await Task.FromResult(result);

        }
    }
}
